package com.zabra.zl.utils;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.zabra.zl.R;

import java.util.Date;
import java.util.List;

public class SelectorUtils {
    public static TimePickerView pvCustomTime;

    public static void initCustomTimePickerStart(Context context, TextView textView, String dateType) {
        //时间选择器 ，自定义布局
        pvCustomTime = new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                textView.setText(DateUtils.getHM(date, dateType));
            }
        })
                .setLayoutRes(R.layout.pickerview_custom_time, new CustomListener() {

                    @Override
                    public void customLayout(View v) {
                        TextView tvSubmit = v.findViewById(R.id.tv_finish);
                        TextView ivCancel = v.findViewById(R.id.tv_cancle);
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomTime.returnData();
                                pvCustomTime.dismiss();
                            }
                        });
                        ivCancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomTime.dismiss();
                            }
                        });
                    }
                })
                .setContentTextSize(18)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("年", "月", "日", "时", "分", "秒")
                .setLineSpacingMultiplier(1.2f)
                .setTextXOffset(0, 0, 0, 40, 0, -40)
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setDividerColor(Color.parseColor("#999999"))
                .build();
        pvCustomTime.show();
    }

    public static void chooseType(Context context, TextView textView, List<String> list) {
        OptionsPickerView pvNoLinkOptions = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                textView.setText(list.get(options1));
            }
        }).setCancelColor(Color.parseColor("#999999"))
                .setSubmitColor(Color.parseColor("#ff3025"))
                .setTitleBgColor(Color.parseColor("#ffffff"))
                .setContentTextSize(14)
                .setSubCalSize(14)
                .setContentTextSize(18)
                .build();
        pvNoLinkOptions.setNPicker(list, null, null);
        pvNoLinkOptions.show();

    }

}
